package com.pentalog.bo.impl;

import java.io.IOException;

import javax.xml.transform.TransformerException;

import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.SoapMessage;

import com.pentalog.bo.ExSoapClient;
import com.pentalog.domain.BookRequest;
import com.pentalog.domain.BookResponse;

public class ExSoapClientImpl extends WebServiceGatewaySupport implements
		ExSoapClient {
	
	
	public BookResponse getBook(String id) {
		String wsdlUri = "http://localhost:8080/SoapSpring/soap/bookservices/book.wsdl";
		BookRequest bookRequest = new BookRequest();
		bookRequest.setItemCode(id);

		BookResponse bookResponse = (BookResponse) getWebServiceTemplate()
				.marshalSendAndReceive(wsdlUri, bookRequest, new WebServiceMessageCallback() {
					
					@Override
					public void doWithMessage(WebServiceMessage message) throws IOException,
							TransformerException {
						// TODO Auto-generated method stub
						System.out.println(((SoapMessage)message).getEnvelope().getBody().toString());
						
					}
				});
		return bookResponse;
	}
}
